<script setup>
import { ref } from "vue";
import { useStore } from "../../store/store";
import { onShow } from "@dcloudio/uni-app";
const store = useStore();
const src = ref("");
src.value = uni.getStorageSync("agent").agentImg || "../../static/agentImg.png";
if (!uni.getStorageSync("token")) {
  uni.navigateTo({ url: "/pages/login/index" });
}
onShow(() => {
  console.log(1);
  src.value = uni.getStorageSync("agent").agentImg || "../../static/agentImg.png";
});
const goUserInfo = () => {
  if (!uni.getStorageSync("token")) {
    return uni.navigateTo({ url: "/pages/login/index" });
  }
  uni.navigateTo({ url: "/pages/mine/userInfo" });
};
const goOut = () => {
  uni.navigateTo({ url: "/pages/login/index" });
  store.clearProfile();
  uni.clearStorageSync();
};
</script>

<template>
  <view class="page">
    <view class="info">
      <view class="user">
        <image class="avatar" :src="src ? src : '../../static/agentImg.png'" mode="" />
        <view class="message">
          <text class="name">{{ store.userInfo.name || "未登录" }}</text>
          <text>{{
            store.userInfo.agentProduct ? store.userInfo.agentProduct.productName : ""
          }}</text>
          <!-- <text>高级合伙人</text> -->
        </view>
      </view>
      <view class="edit" @click="goUserInfo">编辑资料</view>
    </view>
    <button class="btn" @click="goOut">退出登录</button>
  </view>
</template>

<style lang="scss" scoped>
.page {
  background-color: #fff;
  .btn {
    width: 690rpx;
    height: 88rpx;
    text-align: center;
    line-height: 88rpx;
    background-color: rgb(64, 158, 255);
    color: #fff;
    font-size: 32rpx;
    border-radius: 356rpx;
    margin-top: 54rpx;
  }
  .info {
    box-sizing: border-box;
    display: flex;
    justify-content: space-between;
    padding: 30rpx;
    background-color: #fff;
    .user {
      display: flex;
      .avatar {
        width: 120rpx;
        height: 120rpx;
        margin-right: 10rpx;
        border-radius: 50%;
      }
      .message {
        font-size: 24rpx;
        color: rgb(64, 158, 255);
        .name {
          display: block;
          font-size: 40rpx;
          font-weight: 700;
          color: rgb(48, 49, 51);
          margin-bottom: 6rpx;
        }
      }
    }
    .edit {
      font-size: 28rpx;
      color: rgb(69, 70, 74);
      margin-top: 18rpx;
    }
  }
}
</style>
